

let main = {
  formatBirthday(str) {
    let tmp = str.split('-')
    tmp[1] = `00${tmp[1]}`.slice(-2)
    tmp[2] = `00${tmp[2]}`.slice(-2)

    return tmp.join('-')
  },
  toast(text = "") {
    wx.showToast({
      icon: "none",
      title: text
    })
  },
  bitValue(bit, offset = 0) {
    return bit >> offset & 1
  },
  kgTolb(value) {
    return ((((value * 100) * 11023 + 50000) / 100000) << 1) / 10
  },
  kgToJin(value) {
    return value * 2
  },
  unitValueConver(data, unit = 'kg') {
    let valueCalc = () => {}

    if (unit == '斤') {
      valueCalc = main.kgToJin
    } else if (unit == 'lb') {
      valueCalc = main.kgTolb
    } else {
      return data
    }

    data.reportItemList.some(item => {
      if (item.unit == "kg") {
        item.value = valueCalc(item.value)
        item.offset = valueCalc(item.offset)
        item.max = valueCalc(item.max)
        item.min = valueCalc(item.min)
        item.unit = unit
        item.boundaries = item.boundaries.map(_item => {
          return valueCalc(_item)
        })
      }
    })
    return data
  }
}

module.exports = main